/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cgi.ndk.wf.pack;

import com.cgi.ndk.wf.service.TaskServiceBP;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

/**
 *
 * @author kovalcikm
 */
@Service
public class PackageService {

    @Autowired
    private PackageRepository packageRepository;

    @Autowired
    private TaskServiceBP taskService;

    public ResponseEntity<Package> save(@RequestBody Package pack) {
        String uuid = UUID.randomUUID().toString();
        pack.setMid(uuid);
        //create in DB
        ResponseEntity<Package> response = new ResponseEntity<>(packageRepository.save(pack), HttpStatus.CREATED);
        //start humanTask
        taskService.endToEndTest(uuid);

        return response;
    }

    public ResponseEntity<List<Package>> packages() {
        return new ResponseEntity<>(packageRepository.findAll(), HttpStatus.OK);
    }

    public ResponseEntity<Package> getPackage(String id) {
        return new ResponseEntity<>(packageRepository.findOne(id), HttpStatus.OK);
    }
}
